//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.orphan.supplier.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orphan.supplier.mapper.DeliveryInfoMapper;
import com.orphan.supplier.po.DeliveryInfo;
import com.orphan.supplier.po.ListInfo;
import com.orphan.supplier.po.Tender;
import com.orphan.supplier.service.IDeliveryInfoService;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;

@Service("iDeliveryInfoService")
public class DeliveryInfoServiceImpl extends ServiceImpl<DeliveryInfoMapper, DeliveryInfo> implements IDeliveryInfoService {
    @Resource
    private DeliveryInfoMapper deliveryInfoMapper;

    public DeliveryInfoServiceImpl() {
    }

    public ListInfo addInfo(int deliveryAmount, String tenderNumber) {
        ListInfo listInfo = null;
        DeliveryInfo deliveryInfo = this.makeInfo(deliveryAmount, tenderNumber);
        boolean flag = this.deliveryInfoMapper.add(deliveryInfo) > 0;
        if (flag) {
//            System.out.println("deliveryInfoMapper.getNewInfo(tenderNumber) = " + deliveryInfoMapper.getNewInfo(tenderNumber));
            listInfo = new ListInfo(deliveryInfoMapper.getNewInfo(tenderNumber));
        }
        return listInfo;
    }

    public List<DeliveryInfo> list() {
        return this.deliveryInfoMapper.findAll();
    }

    public List<DeliveryInfo> thisInfo(String username) {
        return this.deliveryInfoMapper.selectInfoByUser(username);
    }

    @Override
    public List<DeliveryInfo> tenderInfo(String tenderNumber) {
        return deliveryInfoMapper.getByTenderInfo(tenderNumber);
    }

    private DeliveryInfo makeInfo(int deliveryAmount, String tenderNumber) {
        DeliveryInfo deliveryInfo = new DeliveryInfo();
        deliveryInfo.setDeliveryTime(new Date());
        deliveryInfo.setNumber(UUID.randomUUID().toString());
        deliveryInfo.setDeliveryAmount(deliveryAmount);
        Tender tender = new Tender();
        tender.setNumber(tenderNumber);
        deliveryInfo.setTender(tender);
        return deliveryInfo;
    }
}
